<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>配置管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../css/customer_list.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../common/zTree/css/metroStyle/metroStyle.css">
    <link rel="stylesheet" type="text/css" href="../../common/zTree/css/zTreeStyle/zTreeStyle.css">

    <style>
        #roleAuthTable + .layui-table-view .layui-table tbody tr:hover {
            background-color: transparent;
        }
        .layui-form-item .layui-input-inline{
            width: 250px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar layui-form-pane">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">关键字</label>
                        <div class="layui-input-inline mr0">
                            <input id="search_word" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">类型</label>
                        <div class="layui-input-inline">
                            <select id="dictionary_type">
                                <option value="" checked>全部</option>
                                <option value="1">支付方式</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="btnReset" class="layui-btn layui-btn-warm"><i class="layui-icon">&#xe669;</i>重置
                        </button>
                        <button id="btnAdd" class="layui-btn layui-btn-normal icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="infoTable" lay-filter="infoTable"></table>
        </div>
    </div>
</div>
<!-- 表格操作列 -->
<script type="text/html" id="orderTableBar">
    <a class="layui-btn-a bgeee" lay-event="edit" style="color: #fff">修改</a>
    <a class="layui-btn-a bg999" lay-event="del" style="background-color: #FF794E; color: #fff">删除</a>
</script>
<!--新增修改-->
<script type="text/html" id="modifyForm">
    <form lay-filter="modifyForm" class="layui-form model-form">
        <input name="id" hidden/>
        <div class="layui-form-item" id="authType">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-inline">
                <select name="dictionary_type" lay-verify="required" required>
                    <option value="" checked>全部</option>
                    <option value="1" checked>支付方式</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-inline">
                <input name="name" type="text" class="layui-input" lay-verify="required" required autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-inline">
                <input name="sort" placeholder="请输入" type="number" lay-verify="positiveNumber" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <input id="common" name="common" placeholder="" class="layui-input" autocomplete="off"/>
            </div>
        </div>
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button type="button" lay-filter="modifyFormSubmit" lay-submit class="layui-btn">确认</button>
        </div>
    </form>
</script>
<!-- js部分 -->
<script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../common/zTree/js/jquery.ztree.all-3.5.min.js"></script>

<script type="text/javascript" src="../../common/layui/layui2.js"></script>

<script type="text/javascript" src="../../js/main.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'table','admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;

        form.render();
        // 渲染表格
        table.render({
            elem: '#infoTable',
            url: access_baseurl+'Dictionary/getList',
            method:'POST',
            where: {},
            page: true,
            cellMinWidth: 80,
            id:'infoTable',
            cols: [[
                {align: 'center',field: 'name', title: '分类名称'},
                {align: 'center', field: 'type_name',title: '所属类型'},
                {align: 'center',field: 'common', title: '备注'},
                {align: 'center',field: 'sort', title: '序号'},
                {align: 'center',toolbar: '#orderTableBar',title: '操作',width:170,unresize: true,fixed: 'right'}
            ]],
            done: function (res, curr, count) {
            }

        });
        $('#btnAdd').click(function () {
            showEditModel();
        });

        // 搜索按钮点击事件
        $('#btnSearch').click(function () {
            var where = getWhere();
            table.reload('infoTable', {where: where});
        });

        $('#btnReset').click(function () {
            $('#search_word').val('');
            $('#dictionary_type').val('');
            form.render();
            var where = getWhere();
            table.reload('infoTable', {where:where});
        });

        // 工具条点击事件
        table.on('tool(infoTable)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if(layEvent === 'edit'){
                showEditModel(data);
            }else if(layEvent === 'del'){
                layer.confirm('确定删除吗？', {
                    skin: 'layui-layer-admin'
                }, function (i) {
                    layer.close(i);
                    layer.load(2);
                    var where = getWhere();
                    send_req('Dictionary/del', {id:data.id}, function (res) {
                        layer.msg('操作成功', {icon: 1});
                        layer.closeAll('loading');
                        layer.closeAll('page');
                        table.reload('infoTable', {where: where});
                    });
                    return false;
                });
            }
        });

        // 表单提交
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '500px',
                offset: '65px',
                title: data ? '修改' : '添加',
                content: $('#modifyForm').html(),
                success: function (layero, index) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    if (data) {
                        form.val('modifyForm', data);
                    }
                    form.render();
                }
            });
        }

        form.on('submit(modifyFormSubmit)', function (d) {
            send_req('Dictionary/dictionaryModify', d.field, function (res) {
                layer.msg('操作成功', {icon: 1});
                layer.closeAll('page');
                var where = getWhere();
                table.reload('infoTable', {where: where});
            });
            return false;
        });

        function getWhere() {
            var search_word = $('#search_word').val();
            var dictionary_type = $('#dictionary_type').val();
            var where = {
                search_word:search_word,
                type: dictionary_type
            };
            return where;
        }
    });
</script>
</body>
</html>